<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=windows-1251" />
    <title>Sign VK</title>
    <base href="http://vkontakte.ru/" target="_blank" />
    <link rel="stylesheet" href="http://vkontakte.ru/css/rustyle.css" type="text/css" />
    <link rel="stylesheet" href="http://vkontakte.ru/css/wiki.css" type="text/css" />
    <!--[if lte IE 6]><style type="text/css" media="screen">/* <![CDATA[ */ @import url(http://vkontakte.ru/css/ie.css); /* ]]> */</style><![endif]-->
    <!--[if IE 7]><style type="text/css" media="screen">/* <![CDATA[ */ @import url(http://vkontakte.ru/css/ie7.css); /* ]]> */</style><![endif]-->
    <!--[if gte IE 8]><style type="text/css" media="screen">/* <![CDATA[ */ @import url(http://vkontakte.ru/css/ie8.css); /* ]]> */</style><![endif]-->
    <script src="http://vkontakte.ru/js/common.js"></script>
<!--     <link rel="stylesheet" href="http://durov.at/css/openapi_sample.css" type="text/css" />
    <script src="http://durov.at/js/openapi_sample.js"></script>  -->
  </head>
  <body>
    <div id="vk_api_transport"></div>
    <script type="text/javascript">
	function doLogin() {
  VK.Auth.login(
    null,
    1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048
  );
}

function doLogout() {
  VK.Auth.logout(logoutOpenAPI);
}

function loginOpenAPI() {
  getInitData();
}

function logoutOpenAPI() {
  window.location = baseURL;
}

      window.vkAsyncInit = function() {
        VK.Auth.getLoginStatus(function(response) {
          if (response.session) {
            window.location = baseURL + '';
          } else {
            VK.UI.button('vk_login');
          }
        });
        VK.Observer.subscribe('auth.login', function(response) {
          window.location = baseURL + '';
        });
        VK.Observer.subscribe('auth.logout', function() {
          //console.log('logout');
        });
        VK.Observer.subscribe('auth.statusChange', function(response) {
          //console.log('statusChange');
        });
        VK.Observer.subscribe('auth.sessionChange', function(r) {
          //console.log('sessionChange');
        });
        
        VK.init({
          apiId: {{APP_ID}},
          nameTransportPath: '/xd_receiver.html'
        });
        VK.UI.button('vk_login');
      };
      setTimeout(function() {
        var el = document.createElement('script');
        el.type = 'text/javascript';
        el.src = 'http://vkontakte.ru/js/api/openapi.js';
        el.async = true;
        document.getElementById('vk_api_transport').appendChild(el);
      }, 0);
    </script>
	{% if current_user_vk %}
	  <div id="vk_login" style="margin: 0 auto 20px auto;" onclick="doLogout();"></div>
	{% else %}
      <div id="vk_login" style="margin: 0 auto 20px auto;" onclick="doLogin();"></div>
	  {% endif %}
	  </div>
  </body>
</html>